#include <algorithm>
#include "OpenHeap.h"

	OpenHeap::OpenHeap(bool (*c)(node const*, node const*)) : open(), compare(c)
	{
	}

	bool OpenHeap::empty() const
	{
		return open.empty();
	}

	void OpenHeap::clear()
	{
		open.clear();
	}

	std::size_t OpenHeap::size() const
	{
		return open.size();
	}

	void OpenHeap::push(node* snode)
	{
		open.insert(std::upper_bound(open.begin(), open.end(), snode, compare), snode);
	}

	node* OpenHeap::front() const
	{
		return open.back();
	}

	void OpenHeap::pop()
	{
		open.pop_back();
	}

	void OpenHeap::remove(node const* snode)
	{
		open.erase(std::remove(open.begin(), open.end(), snode), open.end());
	}

	void OpenHeap::enumerate(std::vector<node const*>& sorted) const
	{
		sorted.resize(open.size());
		std::copy(open.begin(), open.end(), sorted.begin());
	}
